package com.senseilearning.sensei;

import java.util.Locale;
import android.content.Context;
import android.speech.tts.TextToSpeech;

public class TtsHandler extends TextToSpeech{
	private boolean succes;
	private String language;
	private String country;
	
	
	public TtsHandler(Context context, OnInitListener listener, String lang1, String lang2) {
		super(context, listener);
		this.language = lang1;
		this.country = lang2;
	}

	public void init(int status){
		if (status == TextToSpeech.SUCCESS) {
			Locale loc = new Locale(language, country);
			int result = this.setLanguage(loc);
			if (result == TextToSpeech.LANG_MISSING_DATA
					|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
				succes = false;
			}
			else {
				succes = true;
			}
		} else {
			succes = false;
		}
	}
	
	public void speakOut(String text){
		if(succes){
			speak(text, TextToSpeech.QUEUE_FLUSH, null);
		} 
	}
	
}
